<?php
class kst_promo_poin_model extends MY_Model {
	var $model = 'kst_promo_poin';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	kst_promo_poin 
					WHERE	(UPPER(pp_id) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(kt_nama) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(perusahaan_nama) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_keterangan) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_tunai) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_tunai_pcs) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_kredit) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_kredit_pcs) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_value) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_awal) LIKE '%".strtoupper(post('keyword'))."%'
						OR UPPER(pp_akhir) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'pp_id' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('kst_promo_poin', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('kst_promo_poin', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_pp_id){
		$result = $this->db->get_where('kst_promo_poin', array('pp_id' => $as_pp_id));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_pp_id)
	{
		$result = $this->db->get_where('kst_promo_poin', array('pp_id' => $as_pp_id));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM kst_promo_poin WHERE pp_id = '".$arr_rule['pp_id']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['pp_id']."]<br />";
			}else{
				$this->db->delete('kst_promo_poin', array('pp_id' => $arr_rule['pp_id']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>